﻿using System;
using System.Reflection;
namespace Nereus.Power {
    public static class NExtenstion {
        public static T GetNAttribute<T>(this Type type) where T : Attribute {
            object[] customAttributes = type.GetCustomAttributes(typeof(T), false);
            if(customAttributes.Length > 0) {
                return (customAttributes[0] as T);
            }
            return default(T);
        }

        public static T GetNAttribute<T>(this MethodInfo mi) where T : Attribute {
            object[] customAttributes = mi.GetCustomAttributes(typeof(T), false);
            if(customAttributes.Length > 0) {
                return (customAttributes[0] as T);
            }
            return default(T);
        }

        public static T GetNAttribute<T>(this PropertyInfo pi) where T : Attribute {
            object[] customAttributes = pi.GetCustomAttributes(typeof(T), false);
            if(customAttributes.Length > 0) {
                return (customAttributes[0] as T);
            }
            return default(T);
        }
        
    }
}
